 package com.xdwanj.studentsystem;

/*
* 这个类对学生对象进行操作*/

public class StudentBiz {
    Student[] stu = new Student[3];

    public void setStu(Student[] stu) {
        this.stu = stu;
    }

    /**
     * 添加名字
     * @param name
     * @return boolean
     */
    public boolean setName(String name) {
        for (int i = 0; i < stu.length; i++) {
            if (this.stu[i].name == null) {
                this.stu[i].name = name;
                return true;
            }
        }
        return false;
    }

    /**
     * 更改姓名
     * @param name
     * @return boolean
     */
    public boolean changeName(String name) {
        for (int i = 0; i < stu.length; i++) {
            if (name.equals(this.stu[i].name)) {
                this.stu[i].name = name;
                return true;
            }
        }
        return false;
    }

    /**
     * 删除姓名
     * @param name
     * @return boolean
     */
    public boolean DeleteName(String name) {
        for (int i = 0; i < stu.length; i++) {
            if (name.equals(this.stu[i].name)) {
                this.stu[i].name = null;
                return true;
            }
        }
        return false;
    }

    /**
     * 判断平均成绩
     * @param
     * @return avg
     */
    public int ScoreAvg() {
        int num = 0;
        for (Student student : stu) {
            num += student.score;
        }
        return num/stu.length;
    }

    /**
     * 判断最大成绩
     * @param
     * @return max
     */
    public int ScoreMax() {
        int max = stu[0].score;
        for (Student student : stu) {
            if (max < student.score)
                max = student.score;
        }
        return max;
    }

    /**
     * 判断最小成绩
     * @param
     * @return min
     */
    public int scoreMin() {
        int min = stu[0].score;
        for (Student student : stu) {
            if (min > student.score)
                min = student.score;
        }
        return min;
    }
}
